﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using ArbabTravelsERP.DAL;

namespace LMS.DataAccessLayer
{
    public class Menu_DAL
    {
        DataUtility du = new DataUtility();


        public DataSet GetMenu(string Is_Parent, string PARENT_MENU_ID, string LMS_MENU_ID, string strMenu)
        {
            SqlParameter[] param = new SqlParameter[4];

            param[0] = new SqlParameter("@IS_PARENT", Is_Parent);
            param[1] = new SqlParameter("@PARENT_MENU_ID", PARENT_MENU_ID);
            if (strMenu == "Parent")
                param[2] = new SqlParameter("@CONDITIONAL_OPERATOR", "Get_PARENT_MENU");
            else
                param[2] = new SqlParameter("@CONDITIONAL_OPERATOR", "Get_MENU");
            param[3] = new SqlParameter("@LMS_MENU_ID", LMS_MENU_ID);

            return du.ExecuteDataSet("StoredProcedure", "PROC_MENU", param);
        }

        public string AddMenu(string MENU_NAME, string MENU_TITLE, string PAGE_NAME, string CONTROLLER_NAME, string PARENT_MENU_ID, bool IS_PARENT, string REMARK, string LMS_MENU_ID, string Action)
        {
            SqlParameter[] param = new SqlParameter[11];

            param[0] = new SqlParameter("@MENU_NAME", MENU_NAME);
            param[1] = new SqlParameter("@MENU_TITLE", MENU_TITLE);
            param[2] = new SqlParameter("@PAGE_NAME", PAGE_NAME);
            param[3] = new SqlParameter("@CONTROLLER_NAME", CONTROLLER_NAME);
            param[4] = new SqlParameter("@PARENT_MENU_ID", PARENT_MENU_ID);
            param[5] = new SqlParameter("@IS_PARENT", IS_PARENT);
            param[6] = new SqlParameter("@CREATED_BY", "1");
            param[7] = new SqlParameter("@CREATED_Date", DateTime.Now);
            param[8] = new SqlParameter("@REMARK", REMARK);
            param[9] = new SqlParameter("@LMS_MENU_ID", LMS_MENU_ID);
            if (Action == "Add")
                param[10] = new SqlParameter("@CONDITIONAL_OPERATOR", "ADD_MENU");
            else if (Action == "Delete")
                param[10] = new SqlParameter("@CONDITIONAL_OPERATOR", "Delete_MENU");
            else
                param[10] = new SqlParameter("@CONDITIONAL_OPERATOR", "EDIT_MENU");

            return du.ExecuteScalardb("StoredProcedure", "PROC_MENU", param);
        }

        public DataTable DislpayAppliedMenuList(string ChannelCode, string CHANNEL_USER_TYPE_ID)
        {
            SqlParameter[] param = new SqlParameter[3];
            param[0] = new SqlParameter("@CHANNEL_CODE", ChannelCode);
            param[1] = new SqlParameter("@USER_TYPE_ID", CHANNEL_USER_TYPE_ID);
            param[2] = new SqlParameter("@CONDITIONAL_OPERATOR", "GET_USER_MENU");
            return du.ExecuteDataTable("StoredProcedure", "PROC_MENU", param);
        }

        public string MenuInsertionByUserType(int USER_TYPE_ID, int MENU_ID, string Created_By, string Action)
        {
            SqlParameter[] param = new SqlParameter[4];

            param[0] = new SqlParameter("@MENU_ID", MENU_ID);
            param[1] = new SqlParameter("@USER_TYPE_ID", USER_TYPE_ID);
            param[2] = new SqlParameter("@CREATED_BY", Created_By);
            if (Action == "Add")
                param[3] = new SqlParameter("@CONDITIONAL_OPERATOR", "ADD_MENU_FOR_USERTYPE");
            else
                param[3] = new SqlParameter("@CONDITIONAL_OPERATOR", "DEL_MENU_FOR_USERTYPE");

            return du.ExecuteScalardb("StoredProcedure", "PROC_MENU", param);
        }

        public DataTable LayoutMenu(string USER_TYPE_ID)
        {
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@USER_TYPE_ID", USER_TYPE_ID);
            param[1] = new SqlParameter("@CONDITIONAL_OPERATOR", "Layout_Menu");
            return du.ExecuteDataTable("StoredProcedure", "PROC_MENU", param);
        }

    }
}